package com.channelsoft.cm.application;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class HomeActivity extends Activity {
	private ListView listView;
	private List<Map<String, Object>> data;
	private Intent intent;
	private ImageButton btn_cancelAuto;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.home);
		listView = (ListView) findViewById(R.id.home_list);
		btn_cancelAuto = (ImageButton) findViewById(R.id.btn_cancelAuto);
		btn_cancelAuto.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				SharedPreferences preferences = getSharedPreferences("login",
						Context.MODE_PRIVATE);
				Editor editor = preferences.edit();
				editor.putBoolean("autoLogin", false);
				editor.commit();
			}
		});
		data = getDataList();
		ListAdapter adapter = new SimpleAdapter(this, data, R.layout.home_item,
				new String[] { "pic" }, new int[] { R.id.home_img }) {
			@Override
			public void setViewImage(ImageView v, int value) {
				super.setViewImage(v, value);
			}
		};
		listView.setDividerHeight(0);
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				switch (position) {
				case 0:
					intent = new Intent();
					intent.setClass(HomeActivity.this, VoiceActivity.class);
					startActivity(intent);
					break;
				}
			}
		});
	}

	public List<Map<String, Object>> getDataList() {
		List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("pic", R.drawable.yyyw);
		data.add(map);
		map.put("pic", R.drawable.sjyw);
		map = new HashMap<String, Object>();
		data.add(map);
		map.put("pic", R.drawable.hfjf);
		map = new HashMap<String, Object>();
		data.add(map);
		map.put("pic", R.drawable.ggcj);
		map = new HashMap<String, Object>();
		data.add(map);
		map.put("pic", R.drawable.qdzs);
		map = new HashMap<String, Object>();
		data.add(map);
		return data;
	}
}
